package cn.tedu.egmybatis2.mapper;

import cn.tedu.egmybatis2.pojo.entity.Customers;
import cn.tedu.egmybatis2.pojo.entity.UserOrders;
import cn.tedu.egmybatis2.pojo.vo.CustomersVO1;
import cn.tedu.egmybatis2.pojo.vo.CustomersVO2;
import cn.tedu.egmybatis2.pojo.vo.CustomersVO3;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CustomersMapper {
    @Insert("INSERT INTO customers(cust_id, cust_tel, cust_name, address) VALUES (#{custId},#{custTel},#{custName},#{address})")
    void insertCustomers(Customers customers);

    @Select("SELECT cust_name as custName, cust_tel as custTel FROM customers WHERE cust_id=#{custId}")
    CustomersVO1 selectByCustId(String custId);

    @Select("SELECT cust_name as custName, address FROM customers WHERE address=#{address}")
    List<CustomersVO2> selectByadd(String address);

    @Select("SELECT b.cust_name, a.order_id, a.amt, a.status FROM user_orders a LEFT JOIN customers b ON a.cust_id = b.cust_id WHERE b.cust_name = #{custName}")
    List<CustomersVO3> selectOrders(String custName);
}
